package com.audition.thread.day02.code;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author xukang
 * @date 2021-03-12 15:11
 * 示范 锁能不能升级
 */
public class CachedDemo {
    final static ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();

    public static void main(String[] args) {
        descend();
    }

    public static void upgrade() {
        rwl.readLock().lock();
        System.out.println("获取到了读锁");
        rwl.writeLock().lock();
        System.out.println("成功升级");
    }public static void descend() {
        rwl.writeLock().lock();
        System.out.println("获取到了写锁");
        rwl.readLock().lock();
        System.out.println("成功降级");
    }
}
